/***************************************************************************
 *          qdefaulthhchandler.cpp - CHM hhc file parser                       *
 *                           -------------------                           *
 *                                                                         *
 *  author:     Nestle <zhurx4g@gmail.com>                         *
 *  notes:      This is a quick hhc file parser.           *
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Lesser General Public License as        *
 *   published by the Free Software Foundation; either version 2.1 of the  *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 ***************************************************************************/

#include "qdefaulthhchandler.h"
QDefaultHHCHandler::QDefaultHHCHandler()
{
    depth = 0;
    result = new QString();
}
QDefaultHHCHandler::~QDefaultHHCHandler()
{
    delete (QString*)result;
}
void QDefaultHHCHandler::startElement(const QString& tagName,const QMap<QString,QString>& attr){
    if(tagName=="ul"||tagName=="UL"){
        depth++;
    }else if(tagName=="object"||tagName=="OBJECT"){

    }else if(tagName=="li"||tagName=="LI"){

    }else if(tagName=="param"||tagName=="PARAM"){
        QString keyName = attr.value("name",QString::null);
        QString keyValue = attr.value("value",QString::null);
        if(keyName=="Name"){
            for(int i=1;i<depth;i++){
                ((QString*)result)->append("    ");
            }
            ((QString*)result)->append(keyValue);
        }else if(keyName=="Local"){
            ((QString*)result)->append("			");
            ((QString*)result)->append(keyValue);
            ((QString*)result)->append("\n");
        }
    }
}
void QDefaultHHCHandler::endElement(const QString& tagName){
    if(tagName=="ul"||tagName=="UL"){
        depth--;
    }
}

void* QDefaultHHCHandler::getTopics(){
    return result;
}

